
#include "copyright.h"

#include "syscall.h"
#include "theaternames.h"

void initializeShared(){

	int i = 0;
	char* str;

	Printing("Beginning Initialization\n", ConsoleOutput, 0,0);

	/* Global Variables */
	
	Printing("Global Variables\n", ConsoleOutput, 0,0);

	
	CreateMonitor(numGroupsName, numGroupsNameLength);
	CreateMonitor(numCustomersName, numCustomersNameLength);

	/* Customer Data "Structure"*/
	
	Printing("Customer Data Structer\n", ConsoleOutput, 0,0);

	CreateMonitor(customerNumberName, customerNumberNameLength);
	CreateMonitor(customerGroupNumberName, customerGroupNumberNameLength);
	
	for(i = 0; i < 100; i++){ /* MAX_MONITOR_VALUES */
		SetMonitor(customerGroupNumberName, customerGroupNumberNameLength, -1, i);
	}
	
	CreateMonitor(customerWantsPopcornName, customerWantsPopcornNameLength);
	CreateMonitor(customerWantsSodaName, customerWantsSodaNameLength);
	CreateMonitor(customerNeedsBathroomName, customerNeedsBathroomNameLength);
	CreateMonitor(customerIsHeadCustomerName, customerIsHeadCustomerNameLength);
	CreateMonitor(customerSeatNumberName, customerIsHeadCustomerNameLength);
	CreateMonitor(customerHasPopcornName, customerHasPopcornNameLength);
	CreateMonitor(customerHasSodaName, customerHasSodaNameLength);
	
	
		
	/*Head Customer Information*/	
	Printing("Head Customer Information\n", ConsoleOutput, 0,0);
	
	CreateMonitor(groupSizeName, groupSizeNameLength);
	CreateMonitor(groupPopcornSizeName, groupPopcornSizeNameLength);
	CreateMonitor(groupSodaSizeName, groupSodaSizeNameLength);
	CreateMonitor(groupBathroomSizeName, groupBathroomSizeNameLength);
	CreateMonitor(groupMoneyName, groupMoneyNameLength);
	CreateMonitor(groupTicketsName, groupTicketsNameLength);
	CreateMonitor(headCustomerNumberName, headCustomerNumberNameLength);
	CreateMonitor(customerStateName, customerStateNameLength);
	
	CreateLock(customerStateLockName, customerStateLockNameLength);

	/*HeadCustomer - Regular Customer Interaction*/

	Printing("HeadCustomer Reg Customer Interaction\n", ConsoleOutput, 0,0);
	

	for(i = 0; i < MAX_GROUPS*4; i++){
	
		CreateLock(headCustomerLockName[i],  headCustomerLockNameLength[i]);
	}
	
	for(i = 0; i < MAX_GROUPS*4; i++){
	
		CreateCondition(headCustomerConditionVariableName[i], headCustomerConditionVariableNameLength[i]);
	}
	
	for(i = 0; i < MAX_GROUPS*4; i++){
	
		CreateCondition(regularCustomerConditionVariableName[i], regularCustomerConditionVariableNameLength[i]);
	
	}
	
	/* Customer Finding Ticket Line */
	
	Printing("Customer Finding Ticket Line\n", ConsoleOutput, 0,0);

	CreateLock(ticketClerkLineLockName, ticketClerkLineLockNameLength);
	
	for(i = 0; i < MAX_TC; i++){
	
		CreateCondition(ticketClerkLineConditionVariableName[i], ticketClerkLineConditionVariableNameLength[i]);
	}
	CreateMonitor(ticketClerkLineCountName, ticketClerkLineCountNameLength);
	CreateMonitor(ticketClerkStateName, ticketClerkStateNameLength);

	/* Customer - TicketClerk Interaction */	
	Printing("Customer - TicketClerk Interaction\n", ConsoleOutput, 0,0);
	
	 for(i = 0; i < MAX_TC; i++){
		
		CreateLock(ticketClerkLockName[i], ticketClerkLockNameLength[i]);
	 
	}
	 
	
	for(i = 0; i < MAX_TC; i++){
			
		CreateCondition(ticketClerkConditionVariableName[i], ticketClerkConditionVariableNameLength[i]);
	 
	}
	
	
	
	CreateMonitor(ticketClerkRegisterName, ticketClerkRegisterNameLength);
	CreateMonitor(ticketClerkNumToSellName, ticketClerkNumToSellNameLength);

	/* Customer Finding Concession Line */
	
	Printing("Customer Finding Concession Line\n", ConsoleOutput, 0,0);
	

	Printing("Customer - TicketClerk Interaction\n", ConsoleOutput, 0,0);
	
	 for(i = 0; i < MAX_TC; i++){
	
		CreateLock(concessionClerkLockName[i], concessionClerkLockNameLength[i]);

	}
	
	CreateLock(concessionClerkLineLockName, concessionClerkLineLockNameLength);

	
	 for(i = 0; i < MAX_CC; i++){
	
		CreateCondition(concessionClerkLineConditionVariableName[i], concessionClerkLineConditionVariableNameLength[i]);
	}
	
	
	CreateMonitor(concessionClerkLineCountName, concessionClerkLineCountNameLength);
	CreateMonitor(concessionClerkStateName, concessionClerkStateNameLength);
	
	/* Customer - ConcessionClerk Interaction */	
	Printing("Customer - Concession Interaction\n", ConsoleOutput, 0,0);	
	
	for(i = 0; i < MAX_CC; i++){

	
	CreateCondition(concessionClerkConditionVariableName[i], concessionClerkConditionVariableNameLength[i]);
	
	}

	CreateMonitor(concessionClerkRegisterName, concessionClerkRegisterNameLength);
	CreateMonitor(concessionClerkPopcornToSellName, concessionClerkPopcornToSellNameLength);
	CreateMonitor(concessionClerkSodaToSellName, concessionClerkSodaToSellNameLength);
	
	/*Customer Finding TicketTaker Line*/
	Printing("Customer Finding TicketTaker Line\n", ConsoleOutput, 0,0);

	CreateLock(ticketTakerLineLockName, ticketTakerLineLockNameLength);
	
	for(i = 0; i < MAX_TT; i++){
	
		CreateCondition(ticketTakerLineConditionVariableName[i], ticketTakerLineConditionVariableNameLength[i]);
	
	
	}
	
	
	CreateMonitor(ticketTakerLineCountName, ticketTakerLineCountNameLength);
	CreateMonitor(ticketTakerStateName, ticketTakerStateNameLength);

	/*Customer - TicketTaker Interaction*/
	Printing("Customer - TicketTaker Interaction\n", ConsoleOutput, 0,0);
	
	for(i = 0; i < MAX_TT; i++){
		
		CreateLock(ticketTakerLockName[i], ticketTakerLockNameLength[i]);

	}
	
	for(i = 0; i < MAX_TT; i++){
	

		CreateCondition(ticketTakerConditionVariableName[i], ticketTakerConditionVariableNameLength[i]);

	}

	CreateMonitor(ticketTakerCounterName, ticketTakerCounterNameLength);
	CreateMonitor(numberAdmittedName, numberAdmittedNameLength);
	
	/* Lobby variables */
	Printing("Lobby Variables\n", ConsoleOutput, 0,0);
	
	CreateCondition(lobbyConditionVariableName, lobbyConditionVariableNameLength);

	/* Total register values */
	Printing("Total Register Values\n", ConsoleOutput, 0,0);
	
	CreateMonitor(ticketMoneyName, ticketMoneyNameLength);
	CreateMonitor(concessionMoneyName, concessionMoneyNameLength);

	/* Customer Finding Seat Interaction*/
	Printing("Customer Finding Seat Interaction\n", ConsoleOutput, 0,0);	
	
	for(i = 0; i < MAX_TT; i++){
	
		CreateCondition(ticketTakerConditionVariableName[i], ticketTakerConditionVariableNameLength[i]);

	}
	for(i = 0; i < ROW_SIZE; i++){
		
		CreateMonitor(roomName[i], roomNameLength[i]); 
	}
	
	CreateMonitor(seatsFilledName, seatsFilledNameLength);
	CreateLock(movieRoomLockName, movieRoomLockNameLength);
	CreateCondition(movieRoomConditionVariableName, movieRoomConditionVariableNameLength);
	
	/* Technician - Customer Interaction */
	Printing("Technician - Customer Interaction\n", ConsoleOutput, 0,0);

	CreateLock(movieDataLockName, movieDataLockNameLength);
	CreateCondition(technicianDataConditionVariableName, technicianDataConditionVariableNameLength);

	/* Manager - Technician Interaction */
	Printing("Manager - Technician Interaction \n", ConsoleOutput, 0,0);

	CreateMonitor(movieStartTimeName, movieStartTimeNameLength);
	CreateMonitor(movieEndedName, movieEndedNameLength);
	CreateMonitor(movieLengthName, movieLengthNameLength);
	
	/* Manager - End Simulation Information */
	Printing("Manager - End Simulation Information\n", ConsoleOutput, 0,0);

	CreateMonitor(custCounterName, custCounterNameLength);
	SetMonitor(custCounterName, custCounterNameLength, 4, 0);
	CreateLock(counterLockName, counterLockNameLength);

	/* Manager - Ticket Clerk break scenario */
	Printing("Manager - Ticket Clerk break scenario\n", ConsoleOutput, 0,0);
	
	/*CreateLock(ticketClerkBreakLockName, ticketClerkBreakLockNameLength);*/
	
	for(i = 0; i < MAX_TC; i++){
	
		CreateLock(ticketClerkBreakLockName[i], ticketClerkBreakLockNameLength[i]);
		CreateCondition(ticketClerkBreakConditionVariableName[i], ticketClerkBreakConditionVariableNameLength[i]);
	}	
	
	
	CreateMonitor(ticketClerkBreakName, ticketClerkBreakNameLength);

	/* Manager - Concession Clerk break scenario */
	Printing("Manager - Concessino Clerk break scenario\n", ConsoleOutput, 0,0);
	
	for(i = 0; i < MAX_CC; i++){
	
		CreateLock(concessionClerkBreakLockName[i], concessionClerkBreakLockNameLength[i]); 
	}	
	
	for(i = 0; i < MAX_CC; i++){
	
		CreateCondition(concessionClerkBreakConditionVariableName[i], concessionClerkBreakConditionVariableNameLength[i]);
	
	}	
	
	
	
	CreateMonitor(concessionClerkBreakName, concessionClerkBreakNameLength);

	/* Manager - Ticket Taker break scenario */
	Printing("Manager - Ticket Taker break scenario", ConsoleOutput, 0,0);
	
	for(i = 0; i < MAX_TT; i++){
		
		CreateLock(ticketTakerBreakLockName[i], ticketTakerBreakLockNameLength[i]);

	}	
	
	for(i = 0; i < MAX_TT; i++){
		
		CreateCondition(ticketTakerBreakConditionVariableName[i], ticketTakerBreakConditionVariableNameLength[i]);

	}	

	CreateMonitor(ticketTakerBreakName, ticketTakerBreakNameLength);/* 1 = on break; 0 = off break; */
	
	/*Bathroom Variables*/
	Printing("Bathroom Variables\n", ConsoleOutput, 0,0);

	
	for(i = 0; i < MAX_GROUPS*4; i++){
	
				
		CreateLock(bathroomLockName[i], bathroomLockNameLength[i]);

	}	
	
	for(i = 0; i < MAX_GROUPS*4; i++){
	
				
		CreateCondition(bathroomLobbyConditionVariableName[i], bathroomLobbyConditionVariableNameLength[i]);

	}
	
	

	/*Index Counters for everyone*/
	Printing("Index Counters for everyone\n", ConsoleOutput, 0,0);
	
	CreateLock(regularCustomerIndexLockName, regularCustomerIndexLockNameLength);
	CreateLock(headCustomerIndexLockName, headCustomerIndexLockNameLength);
	CreateLock(ticketClerkIndexLockName, ticketClerkIndexLockNameLength);
	CreateLock(concessionClerkIndexLockName, concessionClerkIndexLockNameLength);
	CreateLock(ticketTakerIndexLockName, ticketTakerIndexLockNameLength);
	CreateLock(technicianIndexLockName, technicianIndexLockNameLength);
	
	
	
	CreateMonitor(nextRegularCustomerName, nextRegularCustomerNameLength);
	CreateMonitor(nextRegularHeadCustomerName, nextRegularHeadCustomerNameLength);
	CreateMonitor(nextCustomerIndexName, nextCustomerIndexNameLength);
	CreateMonitor(nextHeadCustomerName, nextHeadCustomerNameLength);
	CreateMonitor(nextTicketClerkName, nextTicketClerkNameLength);
	CreateMonitor(nextConcessionClerkName, nextConcessionClerkNameLength);
	CreateMonitor(nextTicketTakerName, nextTicketTakerNameLength);
	CreateMonitor(nextTechnicianName, nextTechnicianNameLength);
	
	Printing("Ending Initialization\n", ConsoleOutput, 0,0);
	
	/*SetMonitor(customersLeftName, customersLeftNameLength, 40, 0);*/
	CreateMonitor(ManagerFinishedName, ManagerFinishedNameLength);

}


int main(){
	int i;
	
	Printing("Regular Customers\n", ConsoleOutput, 0, 0);

	initializeShared();
	
	Exec("../test/HeadCustomer", 20);
	Exec("../test/Manager", 15);
	Exec("../test/RegularCustomer", 23);
	Exec("../test/RegularCustomer", 23);
	Exec("../test/RegularCustomer", 23);
	Exec("../test/TicketClerk", 19);
	Exec("../test/ConcessionClerk", 23);
	Exec("../test/TicketTaker", 19);
	Exec("../test/Technician", 18);

	Exit(1);
}

